Thumb

What is if else condition?

1/8/2020 12:11:39 AM

In the C# programming we have two type of conditional statement. One of the if else statement which is most use the check the condition is true or false. We can use this conditional statement to other purpose by our need. Now given bellow the example code and explain the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using testForClass1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace testFor
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Your Name : ");
            string name = Console.ReadLine();
            Console.WriteLine("Enter Your Id : ");
            int id =Convert.ToInt32(Console.ReadLine());

            if (id == 1 && name == "jesy")
            {
                Console.WriteLine("Welcome farhan sakib !");
            }
            else if (id == 2 && name == "reza")
            {
                Console.WriteLine("Welcome reza karim !");
            }
            else
            {
                Console.WriteLine("Dose not match !");
            }
            Console.Read();
        }
    }
}

In this code we take two value from the console then we check by the if else condition. When value is match of the condition then we print the welcome message but when doesn’t match the value then we go to the only else condition and print the massage.